package apps.sim;

import java.awt.Desktop;
import java.net.URI;
import java.util.Arrays;

import apps.sim.core.log.Console;
import apps.sim.core.log.Console.Color;

public class Index extends BaseIndex {

	public Index() throws Exception {
		super();
		final Splash splash = new Splash("/apps/sim/http/img/shycop-splash.png");
		splash.open(2000);
		final URI uri = new URI(getCurrentURL());
		if (Desktop.isDesktopSupported()) {
			final Desktop desktop = Desktop.getDesktop();
			desktop.browse(uri);
		} else {
			Console.print("Your browser does not support JAVA Desktop API and I'm unable to find your browser.", Color.INFO);
			Console.print("Run \"sudo yum install libgnome\" if you are on Unix, or install \"libgnome\" using your installer.", Color.INFO);
			Console.print("For now. Open this URL in IE or Chrome:" + uri, Color.INFO);
		}
		final String stringValue = "Application instance running [Session ID: " + getSessionID() + "]";
		Console.print(stringValue, Color.INFO);
	}

	public static void main(String[] args) throws Exception {
		try {
			new Index();
		} catch (Throwable cause) {
			cause.printStackTrace();
			Console.print(Arrays.asList(cause.getStackTrace()).toString(), Color.ERROR);
			Console.print("Error: " + cause.getMessage(), Color.ERROR);
			Console.print("Error: another instance is already running", Color.ERROR);
			System.exit(1);
		}
	}

	@Override
	public void killApplication() {
		super.killApplication();
		System.exit(1);
	}
}
